package com.test.fundible.fundible_10_vip;

import android.text.TextUtils;

import com.google.gson.Gson;
import com.test.fundible.R;
import com.test.fundible.fundible_01_launcher.Base_fundibleApplication;
import com.test.fundible.fundible_00_http.OkHttpUtil;


public class Pers_fundibleonalIn_fundiblefo {

    private static class Inner {
        private static Pers_fundibleonalIn_fundiblefo instance = new Pers_fundibleonalIn_fundiblefo();
    }

    private Pers_fundibleonalIn_fundiblefo(){}

    public static Pers_fundibleonalIn_fundiblefo getInstance(){
        return Inner.instance;
    }

    public static void parse_fundible(String userInfo){
        if (!TextUtils.isEmpty(userInfo)) Inner.instance = new Gson().fromJson(userInfo, Pers_fundibleonalIn_fundiblefo.class);
        else {
            Inner.instance = new Pers_fundibleonalIn_fundiblefo();
            Inner.instance.uploadUserInfo(null);
        }
    }

    public void uploadUserInfo(Runnable responseRunnable){
        String data = new Gson().toJson(this);

        if (TextUtils.isEmpty(userAvatar)) userAvatar = "";
        if (expValue<10) expValue = 10;
        else if (expValue>300) expValue = 300;
        if (TextUtils.isEmpty(fullName)) fullName = Base_fundibleApplication.getInstant().getString(R.string.pc_noname);

        OkHttpUtil.getInstance_fundible().uploadUserInfo(data,responseRunnable);
    }

    private String userAvatar = "";//头像（图片链接）
    private int expValue = 10;//经验值
    private String fullName = "";//用户全名
    private boolean repayFlag = false;
    private long lastFeedbackTime = 0;

    public void setUserAvatar(String userAvatar) {
        this.userAvatar = userAvatar;
    }

    public void addExpValue(int increaseExp) {
        if (expValue<10) expValue = 10;
        else if (expValue>300) expValue = 300;

        this.expValue += increaseExp;
    }

    public void setFullName(String fullName) {
        this.fullName = fullName;
    }

    public String getUserAvatar() {
        if (TextUtils.isEmpty(userAvatar)) return "";
        return userAvatar;
    }

    public int getExpValue() {
        return expValue;
    }

    public String getFullName() {
        if (TextUtils.isEmpty(fullName)) return "";
        return fullName;
    }

    public int getGrade(){

        if (expValue>=300) return 3;
        else if (expValue>=100) return 2;

        return 1;
    }

    public int getNextGradeExp(){

        if (expValue<10) expValue = 10;
        else if (expValue>300) expValue = 300;

        if (expValue<100) return 100-expValue;
        else if (expValue<300) return 300-expValue;
        else return 0;

    }

    public boolean getRepayFlag(){
        return repayFlag;
    }

    public void setRepayFlag(boolean repayFlag) {
        this.repayFlag = repayFlag;
    }

    public long getLastFeedbackTime() {
        return lastFeedbackTime;
    }

    public void setLastFeedbackTime(long lastFeedbackTime) {
        this.lastFeedbackTime = lastFeedbackTime;
    }

}
